package com.crayfish.materiallearn;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

/**
 * 作者：crayfish(徐杰)
 * 描述：
 * Created by crayfish on 2017/5/2.
 */

public class MaterialThemeActivity extends Activity {

    private static final int DARK = 1;
    private static final int LIGHT = 2;
    public static int theme = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(theme == DARK){
            setTheme(R.style.darkTheme);
        }else if(theme == LIGHT){
            setTheme(R.style.lightTheme);
        }else{
            setTheme(R.style.MyAppTheme);
        }
        setContentView(R.layout.activity_material);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_material1:
                theme = DARK;
                Toast.makeText(this, "切换后重新进入改变主题", Toast.LENGTH_SHORT).show();
                break;
            case R.id.action_material2:
                theme = LIGHT;
                Toast.makeText(this, "切换后重新进入改变主题", Toast.LENGTH_SHORT).show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
